<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The Yaf_Config_Ini class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="yaf-config-abstract.toarray.html">Yaf_Config_Abstract::toArray</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="yaf-config-ini.construct.html">Yaf_Config_Ini::__construct</a></div>
 <div class="up"><a href="book.yaf.html">Yaf</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.yaf-config-ini" class="reference">

 <h1 class="title">The Yaf_Config_Ini class</h1>
 

 <div class="partintro"><p class="verinfo">(Yaf &gt;=1.0.0)</p>


  <div class="section" id="yaf-config-ini.intro">
   <h2 class="title">简介</h2>
   <p class="para">
   Yaf_Config_Ini允许开发者通过嵌套的对象属性语法在应用程序中用熟悉的INI格式存储和读取配置数据。
   INI格式在提供拥有配置数据键的等级结构和配置数据节之间的继承能力方面具有专长。
   配置数据等级结构通过用点或者句号(.)分离键值。
   一个节可以扩展或者通过在节的名称之后带一个冒号(:)和被继承的配置数据的节的名称来从另一个节继承。
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
   Yaf_Config_Ini利用PHP的函数parse_ini_file()来解析配置文件的。
   请仔细查看这个函数的文档，注意它的一些特殊用途。以及它传递给Yaf_Config_Ini的一些比如
   &quot;TRUE&quot;, &quot;FALSE&quot;,&quot;yes&quot;, &quot;no&quot;, 和&quot;NULL&quot;的特殊值的处理方式
   </p>
  </p></blockquote>
  </p>
  </div>


  <div class="section" id="yaf-config-ini.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">Yaf_Config_Ini</strong>
     </span>
     
     <span class="ooclass">
      <span class="modifier">extends</span>
      <a href="class.yaf-config-abstract.html" class="classname">Yaf_Config_Abstract</a>
     </span>
     
     <span class="oointerface">implements 
      <span class="interfacename"><strong class="interfacename">Iterator</strong></span>
     </span>

     <span class="oointerface">, 
      <span class="interfacename"><strong class="interfacename">Traversable</strong></span>
     </span>

     <span class="oointerface">, 
      <span class="interfacename"><strong class="interfacename">ArrayAccess</strong></span>
     </span>

     <span class="oointerface">, 
      <span class="interfacename"><a href="class.countable.html" class="interfacename">Countable</a></span>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="yaf-config-ini.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$config_file</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$section</code></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.count.html" class="methodname">count</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.current.html" class="methodname">current</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.get.html" class="methodname">__get</a></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.isset.html" class="methodname">__isset</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.key.html" class="methodname">key</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.next.html" class="methodname">next</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.offsetexists.html" class="methodname">offsetExists</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.offsetget.html" class="methodname">offsetGet</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.offsetset.html" class="methodname">offsetSet</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.offsetunset.html" class="methodname">offsetUnset</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.readonly.html" class="methodname">readonly</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.rewind.html" class="methodname">rewind</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.set.html" class="methodname">__set</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.toarray.html" class="methodname">toArray</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="yaf-config-ini.valid.html" class="methodname">valid</a></span>
    ( <span class="methodparam">void</span>
   )</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 继承的方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="type">mixed</span><span class="methodname"><a href="yaf-config-abstract.get.html" class="methodname">Yaf_Config_Abstract::get</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="type">bool</span><span class="methodname"><a href="yaf-config-abstract.readonly.html" class="methodname">Yaf_Config_Abstract::readonly</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="type">Yaf_Config_Abstract</span><span class="methodname"><a href="yaf-config-abstract.set.html" class="methodname">Yaf_Config_Abstract::set</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="type">array</span><span class="methodname"><a href="yaf-config-abstract.toarray.html" class="methodname">Yaf_Config_Abstract::toArray</a></span>
    ( <span class="methodparam">void</span>
   )</div>


   }</div>


  </div>

  

  <div class="section" id="yaf-config-ini.props">
   <h2 class="title">属性</h2>
   <dl>

    
     <dt id="yaf-config-ini.props.config"><var class="varname"><var class="varname">_config</var></var></dt>

     <dd>

      <p class="para"/>
     </dd>

    
    
     <dt id="yaf-config-ini.props.readonly"><var class="varname"><var class="varname">_readonly</var></var></dt>

     <dd>

      <p class="para"/>
     </dd>

    
   </dl>

  </div>


 <div class="section">
  <h2 class="title">范例</h2>
  <div class="example" id="example-4038">
   <p><strong>Example #1 <span class="function"><strong>Yaf_Config_Ini()</strong></span>example</strong></p>
   <div class="example-contents"><p>
    这个例子说明了使用Yaf_Config_Ini从一个INI配置文件中获取配置数据的基本用法。
    这个例子中既有生产环境的配置方法也有演示环境的配置方法。
    因为演示环境的配置跟生产环境的非常类似，所以演示环境的配置继承了生产环境的配置。
    在复杂的情况下，决定是任意的，也可以写成相反的。在更复杂的情况下，生产环境继承自演示环境不是不可能的。
    假设，以下配置数据都包含在/path/to/config.ini中：
   </p></div>
   <div class="example-contents">
<div class="inicode"><pre class="inicode">; Production site configuration data
[production]
webhost                  = www.example.com
database.adapter         = pdo_mysql
database.params.host     = db.example.com
database.params.username = dbuser
database.params.password = secret
database.params.dbname   = dbname
 
; Staging site configuration data inherits from production and
; overrides values as necessary
[staging : production]
database.params.host     = dev.example.com
database.params.username = devuser
database.params.password = devsecret</pre>
</div>
   </div>

   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$config&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Yaf_Config_Ini</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/config.ini'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'staging'</span><span style="color: #007700">);<br />&nbsp;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">database</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">params</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">host</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">database</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">params</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">dbname</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">"database.params.username"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
string(15) &quot;dev.example.com&quot;
string(6) &quot;dbname&quot;
string(7) &quot;devuser
</pre></div>
   </div>
  </div>
  </div>

 </div>

 

















































































































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="yaf-config-ini.construct.html">Yaf_Config_Ini::__construct</a> — 构造函数</li><li><a href="yaf-config-ini.count.html">Yaf_Config_Ini::count</a> — 返回配置的节数量</li><li><a href="yaf-config-ini.current.html">Yaf_Config_Ini::current</a> — 返回当前节点</li><li><a href="yaf-config-ini.get.html">Yaf_Config_Ini::__get</a> — 读取节点配置</li><li><a href="yaf-config-ini.isset.html">Yaf_Config_Ini::__isset</a> — 检查节点是否存在</li><li><a href="yaf-config-ini.key.html">Yaf_Config_Ini::key</a> — 返回当前元素的键</li><li><a href="yaf-config-ini.next.html">Yaf_Config_Ini::next</a> — 向前移动到下一个元素</li><li><a href="yaf-config-ini.offsetexists.html">Yaf_Config_Ini::offsetExists</a> — 检查一个偏移位置是否存在</li><li><a href="yaf-config-ini.offsetget.html">Yaf_Config_Ini::offsetGet</a> — 获取一个偏移位置的值</li><li><a href="yaf-config-ini.offsetset.html">Yaf_Config_Ini::offsetSet</a> — 设置一个偏移位置的值</li><li><a href="yaf-config-ini.offsetunset.html">Yaf_Config_Ini::offsetUnset</a> — 复位一个偏移位置的值</li><li><a href="yaf-config-ini.readonly.html">Yaf_Config_Ini::readonly</a> — 检查配置是否只读</li><li><a href="yaf-config-ini.rewind.html">Yaf_Config_Ini::rewind</a> — 检查当前位置是否有效</li><li><a href="yaf-config-ini.set.html">Yaf_Config_Ini::__set</a> — The __set purpose</li><li><a href="yaf-config-ini.toarray.html">Yaf_Config_Ini::toArray</a> — 转换为数组的格式</li><li><a href="yaf-config-ini.valid.html">Yaf_Config_Ini::valid</a> — 检查迭代器是否有效</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="yaf-config-abstract.toarray.html">Yaf_Config_Abstract::toArray</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="yaf-config-ini.construct.html">Yaf_Config_Ini::__construct</a></div>
 <div class="up"><a href="book.yaf.html">Yaf</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
